package com.cjjd.c.feature.mine.membercard;

import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseSwipeRefreshFragment;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.ListResult;
import com.cjjd.c.bean.MemberCardItemBean;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.FragmentUtil;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/15.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class MemberCardFragment extends BaseSwipeRefreshFragment implements View.OnTouchListener {

    private ListResult<MemberCardItemBean> listData;

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }

    @Override
    public Object getTitleString() {
        return "酒店会员卡包";
    }


    @Override
    protected void initView() {
        super.initView();
        //swipeBaseContent.setOnTouchListener(this);
        listBase.setDivider(null);
        listBase.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MemberCardDetailFragment memberCardDetailFragment = new MemberCardDetailFragment();
                memberCardDetailFragment.setDetail(listData.dataList.get(position));
                FragmentUtil.replaceWithAddToBack(mContext, memberCardDetailFragment, R.id.activity_body);
            }
        });
    }

    @Override
    public void responseSuccess(Call<HttpResult> call, Response<HttpResult> response) {
        listData = (ListResult<MemberCardItemBean>) response.body().getData();
        setDataList(listData.dataList);
    }

    @Override
    public MyBaseAdapter getAdapter() {
        return new MembercardAdapter(mContext);
    }

    @Override
    public Call<HttpResult> getCall() {
//        List list = new ArrayList();
//        list.add("1");
//        list.add("2");
//        setDataList(list);
//        return null;
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("nowPage", PAGE + "");
        h1.put("pageShow", PAGE_SIZE + "");

        return service.getCustomerCardList(JsonUtils.convertParam("getCustomerCardList", h1));
    }
}
